'''
Created on 2011-12-1

@author: latios
'''

p=None

def start(path,port,deffile):
    global p
    import subprocess
    import os
    import wmi
    path = os.path.abspath(path)
    
    c = wmi.WMI()
    iwslst = [pr for pr in c.Win32_Process() if pr.Name=='iws.exe']
    if (iwslst.__len__()==0):
        print 'starting iws.exe on port:%d, at path:%s' %(port,path)
        p=subprocess.Popen('iws path="%(path)s" port=%(port)d deffile="%(deffile)s"' % 
                         {'path':os.path.abspath(path),'port':port,'deffile':deffile})
    else:
        p=None
        print 'iws.exe is already running'
        
def stop():
    global p
    if (p!=None):p.kill()
    